//
//  CartViewTableViewCell.m
//  jingjing2.0
//
//  Created by apple on 16/5/9.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "CartViewTableViewCell.h"

@implementation CartViewTableViewCell
{
    NSIndexPath *_index;
}
- (void)awakeFromNib {
    [super awakeFromNib];
   
   
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

- (IBAction)minNumber:(id)sender
{
    CustomButton *btn=sender;
    //因为索引是根据数据源动态变化的，最好不要用tag记录btn所在哪一行
    if ([btn.superview.superview.superview.superview isKindOfClass:[UITableView class]])
    {
        UITableView *tableView=(UITableView *)btn.superview.superview.superview.superview;
        if ([btn.superview.superview isKindOfClass:[CartViewTableViewCell class]])
        {
            _index=[tableView indexPathForCell:(UITableViewCell *)btn.superview.superview];
        }
    }

    NSInteger count=[self.number.text integerValue];
    count-=1;
    //改变数字
    self.number.text=[NSString stringWithFormat:@"%ld",(long)count];
    btn.title=self.name.text;
    _deletaBlock(_index.row,btn.title,count,NO);
}

- (IBAction)addNumber:(id)sender
{
    CustomButton *btn=sender;
    NSInteger count=[self.number.text integerValue];
    count+=1;
    //上限99
    self.number.text=[NSString stringWithFormat:@"%ld",(long)count];
    btn.title=self.name.text;
      _deletaBlock(_index.row,btn.title,count,YES);
}
@end
